<?php
class AdminController extends Controller {
	public function __construct(){
		parent::__construct();
		if($this->router->action!='index'){
			$this->islogin();
			$this->isaccess();
		}
		$this->helper(array('cookie'));
	}
	public function index() {
		//print_r($_GET);
		$this->show('admin/login.php');
	}
	public function main() {
		$m = $this->model('Menu');
		$u = $this->model('User');
		$this->assign('pcarr',$m->getmenu());
		$this->assign('diyarr',$m->getdiy());
		$this->assign($u->getoneuser(get_cookie('u_id')));
		$this->show('admin/admin.php');
	}
	public function adminindex() {
		$data = $this->model('Serverdata');
		$this->assign($data->getserverinfo());
		$this->show('admin/default.php');
	}
	public function privilege() {
		$pri = $this->model('Privilege');
		$this->assign('pcarr',$pri->getprivilege());
		$this->show('admin/privilege.php');
	}
	public function editprivilege() {
		$pri = $this->model('Privilege');
		$this->assign($pri->getonepriviege());
		$this->assign('catearr',$pri->getprivilegecate());
		if(isset($_GET['pid'])){
			$this->show('admin/editprivilege.php');
		}else{
			$this->show('admin/editprivilegecate.php');
		}
	}
	public function setdiy() {
		$pri = $this->model('Menu');
		$this->assign('pcarr',$pri->getmenu());
		$this->show('admin/setdiy.php');
	}
	public function role() {
		$r = $this->model('Role');
		$this->assign('arr',$r->getrole());
		$this->show('admin/role.php');
	}
	public function editrole() {
		$r = $this->model('Role');
		$this->assign($r->getonerole());
		$this->show('admin/editrole.php');
	}
	public function assignrole() {
		$pri = $this->model('Privilege');
		$r = $this->model('Role');
		$this->assign('rolepri',$r->getprivilegerole());
		$this->assign('pcarr',$pri->getprivilege());
		$this->assign($r->getonerole());
		$this->show('admin/assignrole.php');
	}
	public function users() {
		$u = $this->model('User');
		$this->assign('arr',$u->getuser());
		$this->show('admin/users.php');
	}
	public function adduser() {
		$r = $this->model('Role');
		$this->assign('arr',$r->getrole());
		$this->show('admin/adduser.php');
	}
	public function edituser() {
		$u = $this->model('User');
		$r = $this->model('Role');
		$this->assign('arr',$r->getrole());
		$this->assign($u->getoneuser($_GET['uid']));
		$this->show('admin/edituser.php');
	}
	public function profile() {
		$u = $this->model('User');
		$this->assign($u->getoneuser(get_cookie('u_id')));
		$this->show('admin/editprofile.php');
	}
	public function log() {
		$l = $this->model('Logs');
		$this->assign('arr',$l->getlog());
		$this->show('admin/logs.php');
	}
}